local zhuoling = fk.CreateSkill{
  name = "hanqing__zhuoling",
}

Fk:loadTranslationTable{
  ["hanqing__zhuoling"] = "灼翎",
  [":hanqing__zhuoling"] = "出牌阶段限一次，你可以交换一名角色的手牌与中央区的牌（至少一张），若其手牌数因此减少/增加，"..
  "其对你/你对其造成1点火焰伤害，然后你横置你与其中体力不为较小的角色，若你因此被横置，你移去中央区的牌。",

  ["#hanqing__zhuoling"] = "灼翎：交换一名角色的手牌与中央区的牌",
  ["hanqing__zhuoling_tip_1"] = "对你造成伤害",
  ["hanqing__zhuoling_tip_2"] = "对其造成伤害",
}

local DIY = require "packages/diy_utility/diy_utility"

zhuoling:addEffect("active", {
  anim_type = "offensive",
  prompt = "#hanqing__zhuoling",
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    return #Fk:currentRoom():getBanner("@$CenterArea") > 0 and
      player:usedSkillTimes(zhuoling.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function (self, player, to_select, selected, selected_cards)
    return #selected == 0
  end,
  target_tip = function (self, player, to_select, selected, selected_cards, card, selectable, extra_data)
    if not selectable then return end
    if to_select:getHandcardNum() > #Fk:currentRoom():getBanner("@$CenterArea") then
      return { {content = "hanqing__zhuoling_tip_1", type = "warning"} }
    elseif to_select:getHandcardNum() < #Fk:currentRoom():getBanner("@$CenterArea") then
      return { {content = "hanqing__zhuoling_tip_2", type = "normal"} }
    end
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local from, to
    if target:getHandcardNum() > #room:getBanner("@$CenterArea") then
      from, to = target, player
    elseif target:getHandcardNum() < #room:getBanner("@$CenterArea") then
      from, to = player, target
    end
    room:swapCardsWithPile(target, target:getCardIds("h"), room:getBanner("@$CenterArea"), zhuoling.name, "discardPile", true, player)
    if from == nil then return end
    if not to.dead then
      room:damage {
        from = from,
        to = to,
        damage = 1,
        damageType = fk.FireDamage,
        skillName = zhuoling.name,
      }
    end
    if not player.dead and player.hp >= target.hp and not player.chained then
      if player:setChainState(true) then
        DIY.removeCenterCards(player, room:getBanner("@$CenterArea"))
      end
    end
    if not target.dead and target.hp >= player.hp and not target.chained then
      target:setChainState(true)
    end
  end,
})

return zhuoling
